<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box1,
        #box2 {
            width: 100px;
            height: 100px;
            background-color: aquamarine;
            position: absolute;
        }

        #box2 {
            background-color: blue;
        }
    </style>
    <script src="../面向对象练习/drag.js"></script>
    <script src="../面向对象练习//limitDrag.js"></script>
</head>

<body>
    <div id="box1">
        普通拖拽
    </div>
    <div id="box2">
        限制范围拖拽
    </div>
</body>
<script>
    //面向过程
    // 普通拖拽
    // var box1 = document.getElementsByClassName('box1')
    // var b1x = 0
    // var b1y = 0
    // box1.onmousedown = function (eve) {
    //     var event = eve || window.event
    //     b1x = event.clientX - box1.offsetLeft
    //     b1y = event.clientY - box1.offsetTop
    //     document.onmousemove = function (ev) {
    //         var event = ev || window.event
    //         box1.style.left = event.clientX - b1x + 'px'
    //         box1.style.top = event.clientY - b1y + 'px'
    //     }
    //     document.onmouseup = function () {
    //         document.onmousemove = null
    //     }
    // }

    // 面向对象
    var drag = new Drag('box1')
    var drag2 = new limitDrag('box2')
    drag.init()
    drag2.init()
</script>

</html>